import requests
import re

# 构造请求头
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'
}
# # 案例1：百度搜索
# url=r'https://www.baidu.com/'
# data={'wd':'a6'}
# resp=requests.get(url,params=data,headers=headers)
# resp.encoding="utd-8"
# patt=r'<title>(.*?)</title>'
# title=re.findall(patt,resp.text)
# print(title)
# date={'wd':'a7'}
# resp=requests.post(url,params=date,headers=headers)
# resp.encoding="utd-8"
# patt=r'<title>(.*?)</title>'
# title=re.findall(patt,resp.text)
# print(title)
# # 案例2：手机号归属地 http://apis.juhe.cn/mobile/get
# url=r'http://apis.juhe.cn/mobile/get'
# data={'phone':'18625950557','key':'01d47355efcfcc4fc35d40e1d97bea5c'}
# resp=requests.get(url,params=data,headers=headers)
# print(resp.text)
# url=r'http://apis.juhe.cn/mobile/get'
# data={'phone':'18625950557','key':'01d47355efcfcc4fc35d40e1d97bea5c'}
# resp=requests.post(url,params=data,headers=headers)
# print(resp.text)
# 案例3：天气查询 http://apis.juhe.cn/simpleWeather/query 一个get 一个post
# url=r'http://apis.juhe.cn/simpleWeather/query'
# data={'key':'a5f4564146840503d54f090d28483ad9','city':'新乡'}
# resp=requests.get(url,params=data,headers=headers)
# print(resp.text)
# url=r'http://apis.juhe.cn/simpleWeather/query'
# data={'key':'a5f4564146840503d54f090d28483ad9','city':'封丘'}
# resp=requests.post(url,params=data,headers=headers)
# print(resp.text)